/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hcsc.datapower.CMDB.gui;


import com.hcsc.datapower.CMDB.service.AdminUserManagementController;
import javax.swing.JDialog;
import javax.swing.JPanel;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author I307211
 */
public class AdminUserManagementWindow  extends JDialog{
    
    private static final String NEW_ACTION = "New User";
    private static final String EDIT_ACTION = "Edit User";
    
    private AdminUserManagementController adminusermanagementcontroller;
    /**
     * Creates new form AddUserNew
     */
    public AdminUserManagementWindow() {
        initComponents();
        //center the code
        setLocationRelativeTo(null);
    }

    public void setjButton2_deleteuser(boolean edit) {
        this.jButton2_deleteuser.setVisible(edit);
    }

    public JPanel getjPanel2_usernamepassword() {
        return jPanel2_usernamepassword;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2_usernamepassword = new javax.swing.JPanel();
        jLabel1_username = new javax.swing.JLabel();
        jLabel1_password = new javax.swing.JLabel();
        jTextField1_username = new javax.swing.JTextField();
        jTextField1_password = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jComboBox1_authlevels = new javax.swing.JComboBox();
        jPanel2_personalinfo = new javax.swing.JPanel();
        jLabel1_firstname = new javax.swing.JLabel();
        jLabel1_password1 = new javax.swing.JLabel();
        jTextField1_firstname = new javax.swing.JTextField();
        jTextField1_lastname = new javax.swing.JTextField();
        jButton1_oksubmit = new javax.swing.JButton();
        jButton1_cancel = new javax.swing.JButton();
        jButton2_deleteuser = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1_userlist = new javax.swing.JList();

        jPanel2_usernamepassword.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1_username.setText("Username");

        jLabel1_password.setText("Password");

        javax.swing.GroupLayout jPanel2_usernamepasswordLayout = new javax.swing.GroupLayout(jPanel2_usernamepassword);
        jPanel2_usernamepassword.setLayout(jPanel2_usernamepasswordLayout);
        jPanel2_usernamepasswordLayout.setHorizontalGroup(
            jPanel2_usernamepasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2_usernamepasswordLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2_usernamepasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1_username)
                    .addComponent(jLabel1_password))
                .addGap(18, 18, 18)
                .addGroup(jPanel2_usernamepasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1_username, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField1_password, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2_usernamepasswordLayout.setVerticalGroup(
            jPanel2_usernamepasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2_usernamepasswordLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2_usernamepasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1_username)
                    .addComponent(jTextField1_username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2_usernamepasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1_password)
                    .addComponent(jTextField1_password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Authorization Level"));

        jComboBox1_authlevels.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Read", "Update", "Admin" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox1_authlevels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jComboBox1_authlevels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 12, Short.MAX_VALUE))
        );

        jPanel2_personalinfo.setBorder(javax.swing.BorderFactory.createTitledBorder("Personal Info"));

        jLabel1_firstname.setText("First Name");

        jLabel1_password1.setText("Last Name");

        javax.swing.GroupLayout jPanel2_personalinfoLayout = new javax.swing.GroupLayout(jPanel2_personalinfo);
        jPanel2_personalinfo.setLayout(jPanel2_personalinfoLayout);
        jPanel2_personalinfoLayout.setHorizontalGroup(
            jPanel2_personalinfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2_personalinfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2_personalinfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1_firstname)
                    .addComponent(jLabel1_password1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2_personalinfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1_firstname, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField1_lastname, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(97, Short.MAX_VALUE))
        );
        jPanel2_personalinfoLayout.setVerticalGroup(
            jPanel2_personalinfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2_personalinfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2_personalinfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1_firstname)
                    .addComponent(jTextField1_firstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2_personalinfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1_password1)
                    .addComponent(jTextField1_lastname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2_personalinfo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2_usernamepassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2_usernamepassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2_personalinfo, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButton1_oksubmit.setText("Submit");
        jButton1_oksubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1_oksubmitActionPerformed(evt);
            }
        });

        jButton1_cancel.setText("Cancel");
        jButton1_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1_cancelActionPerformed(evt);
            }
        });

        jButton2_deleteuser.setText("Delete");
        jButton2_deleteuser.setEnabled(false);
        jButton2_deleteuser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2_deleteuserActionPerformed(evt);
            }
        });

        jList1_userlist.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1_userlist);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton2_deleteuser)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1_oksubmit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1_cancel)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1_cancel)
                    .addComponent(jButton1_oksubmit)
                    .addComponent(jButton2_deleteuser))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2_deleteuserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2_deleteuserActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2_deleteuserActionPerformed

    private void jButton1_oksubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1_oksubmitActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1_oksubmitActionPerformed

    private void jButton1_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1_cancelActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButton1_cancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1_cancel;
    private javax.swing.JButton jButton1_oksubmit;
    private javax.swing.JButton jButton2_deleteuser;
    private javax.swing.JComboBox jComboBox1_authlevels;
    private javax.swing.JLabel jLabel1_firstname;
    private javax.swing.JLabel jLabel1_password;
    private javax.swing.JLabel jLabel1_password1;
    private javax.swing.JLabel jLabel1_username;
    private javax.swing.JList jList1_userlist;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel2_personalinfo;
    private javax.swing.JPanel jPanel2_usernamepassword;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1_firstname;
    private javax.swing.JTextField jTextField1_lastname;
    private javax.swing.JTextField jTextField1_password;
    private javax.swing.JTextField jTextField1_username;
    // End of variables declaration//GEN-END:variables

    public AdminUserManagementController getAdminusermanagementcontroller() {
        return adminusermanagementcontroller;
    }

    public void setAdminusermanagementcontroller(AdminUserManagementController adminusermanagementcontroller) {
        this.adminusermanagementcontroller = adminusermanagementcontroller;
    }

    public void setMode(Boolean newuser) {
        if(newuser){
            jList1_userlist.setEnabled(false);
            getjPanel2_usernamepassword().setBorder(javax.swing.BorderFactory.createTitledBorder(NEW_ACTION));
        }else{
            getjPanel2_usernamepassword().setBorder(javax.swing.BorderFactory.createTitledBorder(EDIT_ACTION));
            //load users
        }
    }
    

}
